test(ContainerResource): unit coverage for RestartPolicy + ContainerCreateOptions Codable#1
Open
chrisgeo wants to merge 1 commit into
Conversation
…reateOptions Codable
TestCLIRunRestart already covers end-to-end behavior against a live
daemon. These add a complementary unit-level layer over the wire shape
of 'RestartPolicy' and the forward-compatibility guarantees of
'ContainerCreateOptions':
- encodesAsBareString — '.always' -> "always" (catches accidental
enum-with-associated-value encoding regressions).
- decodesEveryCase — round-trip safety for { no, onFailure, always }.
- rejectsUnknownString — Compose-spec mode 'unless-stopped' is
intentionally NOT in this PR's enum. Test pins that decision: any
downstream tool that emits the broader Docker set fails loudly
rather than silently degrading.
- decodesLegacyOptionsWithoutRestartPolicy — the wire-compat
invariant. An 'options.json' blob written by a daemon that
predates 'restartPolicy' must still decode, defaulting to '.no'.
This locks in the 'decodeIfPresent ?? .no' contract in
ContainerCreateOptions.init(from:) — removing it would silently
break every existing container on disk.
- decodesLegacyOptionsWithAutoRemove — same invariant with a
non-zero pre-existing field present, ensuring the default doesn't
get triggered by unrelated keys.
- roundTripPreservesRestartPolicy — basic options-level round-trip.
- encodedJSONIncludesRestartPolicyField — confirms the field name
matches the CodingKeys declaration (catches typo regressions in
the key enum).
- defaultStaticIsNoRestart — pins '.default' to '.no'.
No production code touched. Verification:
swift build -> Build complete! (69.11s), exit 0.
swift test --filter RestartPolicyTests
-> 8/8 tests passed in 0.001s.
Refs apple#1258.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds unit-level test coverage for
RestartPolicyandContainerCreateOptionsCodable behavior, complementing the existingTestCLIRunRestartend-to-end integration tests in this PR.Why this is useful
TestCLIRunRestartexercises full restart-policy behavior against a live daemon — which is the right end-to-end coverage. But several wire-shape invariants are easier to lock down with fast, daemon-free unit tests:decodesLegacyOptionsWithoutRestartPolicy— the most important test.ContainerCreateOptions.init(from:)usesdecodeIfPresent ?? .noso olderoptions.jsonblobs (written by daemon versions that predate this PR) still decode cleanly. Removing that default in a future refactor would silently break every existing container's options file on disk. This test makes that contract explicit.rejectsUnknownString— Compose-spec includesunless-stopped; this PR deliberately does not. The test pins that decision: any tool emitting the broader Docker set fails loudly with aDecodingErrorinstead of silently degrading. Important for downstream consumers like container-compose that may emit the broader set.encodesAsBareString/encodedJSONIncludesRestartPolicyField— pin the JSON shape so a future contributor can't accidentally regress the bare-string encoding or renameCodingKeys.roundTripPreservesRestartPolicy/decodesEveryCase/defaultStaticIsNoRestart— standard hygiene.Files
Tests/ContainerResourceTests/RestartPolicyTests.swift(new, 107 LoC, 8 tests)No production code touched.
Verification
Apple silicon, macOS 26.
Context
I'm tracking this work from a fork that adopted the SDK shape from this PR (full-chaos#13) and wrote the equivalent unit tests there. After the audit pivot to align the fork with this upstream PR, the tests transfer 1:1. Filing them here directly per your "if you make PR to my branch, let me merge it" invitation upthread. Happy to revise or split if any of these test the wrong layer.
Refs apple#1258, apple#286.